#ifndef _GS_CMU_H
#define _GS_CMU_H

#include "GSStm32F4_Common.h"
#define RASPI_TO_STM32_BUFF_LEN  17


#define GS_SET_485_SE (GPIOA->BSRRH = BIT4)
#define GS_CLR_485_SE (GPIOA->BSRRL = BIT4)

#define GS_SET_485_SE_2 (GPIOA->BSRRH = BIT5)
#define GS_CLR_485_SE_2 (GPIOA->BSRRL = BIT5)


typedef struct{
    union {
    __IO uint32_t w[10];
	    uint8_t d_data[GS_CMU_IN_BUFF_LEN];
    }d_inData;

    union {
    __IO uint32_t w[10];
	    uint8_t d_data[GS_CMU_IN_BUFF_LEN];
    }d_motorInData;
	uint16_t d_len;	
    uint8_t l_Crc32Temp[8];
    uint16_t d_indexRear;
    uint16_t d_indexFront;
    uint8_t d_sentAllow;

    uint8_t d_recAllow;
    uint8_t d_recAllowCnt;
    uint8_t d_handleBuff[RASPI_TO_STM32_BUFF_LEN];
    uint8_t d_sendFlag;
    union {
        __IO uint32_t w;
        uint8_t returnBuff[5][16];
    }reData;
    uint8_t isCmdCfgErr;
    uint8_t isCmdRunErr;
    uint32_t d_sendTime;
    uint8_t d_isSend;
    uint32_t d_errCnt;
    uint32_t d_sendCnt;

    uint32_t d_recCnt;
    uint32_t d_msCnt;
    uint8_t d_recFlag;
    uint32_t d_initSuccessCnt;
    union {
        __IO uint32_t w;
        uint8_t returnBuff[5][16];
    }reDataLast;
    uint32_t     d_isStopCnt;
    uint8_t       d_isCurrentReadFlag;
    uint8_t       d_isPosReadFlag;

} _CMU_485;

extern _CMU_485 g_nanoCmuData;
extern _CMU_485 g_motorCmuData;
extern void g_x485SendBlock(uint8* l_SndBuff,uint16 l_lenth);
extern void g_xNanoSendBlock(uint8* l_SndBuff,uint16 l_lenth);
extern uint8_t g_nanoGetCrc8(uint8_t *ptr, unsigned short len);

extern void MotroTorqueInit(uint8_t l_ID);
extern void g_runOnes(int16_t l_pos,uint8_t l_num);
extern void g_readPos(uint8_t l_id);
extern void g_readCurrent(uint8_t l_id);



extern void g_setParamOnes(int16_t l_param,uint8_t l_num,uint8_t l_index);
extern int8_t g_nanoProcess(void);
extern int8_t g_motorCmuProcess(void);
extern void g_sendToNano(void);
extern void g_nanoDataFill(void);

#endif /*_GS_CMU_H*/